﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using G28BS.Models;

namespace G28BS.Controllers
{
    public class BaseAppController : Controller
    {
        private IAppRepository repo = null;

        public BaseAppController()
        {
            repo = new AppRepository();
        }

        public BaseAppController(IAppRepository r)
        {
            repo = r;
        }

        protected override void OnException(ExceptionContext filterContext)
        {
            // base might want to do something
            base.OnException(filterContext);

            // Log error
            Exception ex = filterContext.Exception;

            var error = new Error { message = ex.Message, source = ex.Source, stackTrace = ex.StackTrace, timestamp = DateTime.Now };
            repo.AddError(error);
            repo.Save();
        }

    }
}
